package com.xxcxcxcx.xc_moremob.common.skills.SkillWololo;

import com.xxcxcxcx.xc_moremob.common.entities.monster.realization.SkillBasicEntity;
import com.xxcxcxcx.xc_moremob.common.skills.Currentskills;
import com.xxcxcxcx.xc_moremob.common.skills.UseskillGoal;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.item.DyeColor;

import java.util.List;
//改变羊的颜色
public class SkillWololoSkillGoal extends UseskillGoal {
    private final TargetingConditions wololoTargeting = TargetingConditions.forNonCombat().range(16.0D).selector((p_32710_) -> {
        return ((Sheep)p_32710_).getColor() == DyeColor.BLUE;
    });

    public SkillWololoSkillGoal(SkillBasicEntity mo) {
        super(mo,40,60,140);
    }
    public SkillWololoSkillGoal(SkillBasicEntity mo, int CastWarmup, int Casting, int CastingInterval){
        super(mo,CastWarmup,Casting,CastingInterval);
    }
    public boolean canUse() {
        if (mob.getTarget() != null) {
            return false;
        } else if (mob.isCastingSpell()) {
            return false;
        } else if (mob.tickCount < this.nextAttackTickCount) {
            return false;
        } else if (!net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(mob.level, mob)) {
            return false;
        } else {
            List<Sheep> list = mob.level.getNearbyEntities(Sheep.class, this.wololoTargeting, mob, mob.getBoundingBox().inflate(16.0D, 4.0D, 16.0D));
            if (list.isEmpty()) {
                return false;
            } else {
                mob.setWololoTarget(list.get(mob.level.getRandom().nextInt(list.size())));
                return true;
            }
        }
    }
    public boolean canContinueToUse() {
        return mob.getWololoTarget() != null && this.attackWarmupDelay > 0;
    }
    public void stop() {
        super.stop();
        mob.setWololoTarget((Sheep)null);
    }
    protected void performSpellCasting() {
        Sheep sheep = mob.getWololoTarget();
        DyeColor color=DyeColor.byId(mob.level.getRandom().nextInt(0,16));
        while (color==DyeColor.BLUE)color=DyeColor.byId(mob.level.getRandom().nextInt(0,16));
        if (sheep != null && sheep.isAlive()) {
            sheep.setColor(color);
        }
    }
    protected SoundEvent getSpellPrepareSound() {
        return SoundEvents.EVOKER_PREPARE_WOLOLO;
    }
    protected Currentskills getSpell() {
        return Currentskills.WOLOLO;
    }
}